package xzy.com.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import xzy.com.dao.MenuMapper;
import xzy.com.entity.domain.Menu;
import xzy.com.service.MenuService;
@Service
public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu>implements MenuService{

	//查询所有父级菜单
	@Override
	public List<Menu> queryParentMenu() {
		QueryWrapper<Menu>queryWrapper=new QueryWrapper<Menu>();
		queryWrapper.eq("parent_id", 0);
		return this.baseMapper.selectList(queryWrapper);
	}

	//查询父级菜单
	@Override
	public IPage<Menu> findParentMenu(Page<Menu> page, QueryWrapper<Menu> wrapper) {
		return this.baseMapper.findParentMenu(page, wrapper);
	}
	
	@Override
	public List<Map<String, Object>> boardList() {
		//查询一级菜单
		List<Map<String, Object>> findDirMenu = this.baseMapper.findDirMenu();
		//查询目录对应的子菜单
		for(Map<String, Object> map:findDirMenu) {
			Long menuId = Long.parseLong(map.get("menuId")+"");
			//拿到子菜单信息
			List<Map<String, Object>>subList=this.baseMapper.findSubMenu(menuId);
			map.put("children", subList);	
		}
		System.out.println("-----------------------");
		System.out.println(findDirMenu);
		return findDirMenu;
	}


}
